package com.xyc.view.controller;


import com.xyc.global.bean.Message;
import com.xyc.global.bean.UserDTO;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import javax.annotation.Resource;

@RestController
@CrossOrigin //允许跨域
@RequestMapping("user")
public class PermissonController {
    @Resource
    private RestTemplate restTemplate;
    @RequestMapping("login")
    public Message login(String username,String password,Integer loginType){
        Message message = new Message();
        UserDTO userDTO = new UserDTO(username,password);
        if (loginType == 0){
            //自媒体登录
            message = restTemplate.postForObject("http://zmt-server/user/login", userDTO, Message.class);
        }else {
            //商户登录
            message = restTemplate.postForObject("http://merchant-server/user/login", userDTO, Message.class);
        }
        return message;
    }
}
